package com.semlab.server.services;

import java.util.List;

import com.semlab.server.domain.MoviePage;
import com.semlab.server.enrichment.*;
import com.semlab.shared.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.semlab.server.domain.Movie;
import com.semlab.server.domain.Client;
import com.semlab.server.graph.Neo4jTemplate;

@Component
public class DataService {
    Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    ImportService insert;

//    @Autowired
//    UpdateConceptsService update;
//
//    @Autowired
//    EnrichConceptsService enrich;

    @Autowired
    EnrichService enrich;

    @Autowired
    DataMiner miner;

    @Autowired
    Neo4jTemplate template;

    public Boolean startImport(Client client, int numOfFriends, int numOfMovies) {
        log.debug("starting import {}", client);
        try {
            insert.process(client.getAccessToken(), numOfFriends, numOfMovies);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

    public Boolean startEnrichment(Client client) {
        log.debug("starting enrichment {}", client);
//        update.process();
        return true;
    }

    public MoviePage getMovies(Client client, int offset, int num) {
        log.debug("retrieving movies {}", client);
        MoviePage page = new MoviePage();
        page.setItems(miner.getFriendsMovies(client.getFacebookId(), offset, num));
        page.setTotal(miner.countFriendsMovies(client.getFacebookId()));
        return page;
    }

    public Movie getDetailsForAMovie(Client client, Movie movie) {
        try {
            return miner.getDetailsForAMovie(movie);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("error={}", e.getMessage());
        }
        return null;
    }

    public Movie enrichMovieData(Movie movie) {
        try {
            return enrich.enrichMovie(movie);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("error={}", e.getMessage());
        }
        return null;
    }

}
